package com.shopcart.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.annotation.LoginFilter;
import com.demo.bean.DataTable;
import com.demo.bean.Ret;
import com.demo.controller.CoreAdminController;
import com.demo.dialet.PaginationSupport;
import com.demo.util.JSONUtils;
import com.demo.validator.AdminLoginValidate;
import com.shopcart.daoEx.model.StoreCommentEx;
import com.shopcart.domain.StoreComment;
import com.shopcart.service.StoreCommentService;

@Controller
@RequestMapping("storeComment")
@LoginFilter(validateClz=AdminLoginValidate.class)
public class StoreCommentController extends CoreAdminController{
	@Autowired
	private StoreCommentService storeCommentService;
 
	
	@RequestMapping("/list")
	@ResponseBody
	public String storeList(HttpSession session,@RequestParam("draw") Integer draw
			,@RequestParam("start") Integer start,@RequestParam("length") Integer length
			,@RequestParam("search[value]") String search,String areaCode,String storeId,HttpServletRequest request){
		
		PaginationSupport.byPage(start/length+1, length);
		
		
		List<StoreCommentEx> list = storeCommentService.selectExList(search, areaCode);
		
		return JSONUtils.serialize(new DataTable(draw+1,PaginationSupport.getContext().getTotalCount(), list));
	}
	
	@RequestMapping("/listByStore")
	@ResponseBody
	public String listByStore(HttpSession session,@RequestParam("draw") Integer draw
			,@RequestParam("start") Integer start,@RequestParam("length") Integer length
			,@RequestParam("search[value]") String search,String areaCode,String storeId,HttpServletRequest request){
		
		PaginationSupport.byPage(start/length+1, length);
		storeId = getSessionParameter("id", session);
		
		List<StoreCommentEx> list = storeCommentService.selectExList(search, areaCode,storeId);
		
		return JSONUtils.serialize(new DataTable(draw+1,PaginationSupport.getContext().getTotalCount(), list));
	}
	

	@RequestMapping("/findById")
	@ResponseBody
	public String findById(String id,HttpServletRequest request){
		StoreComment s = storeCommentService.findById(id);
		return JSONUtils.serialize(s);
	}
	
	 
	
	@RequestMapping("/del")
	@ResponseBody
	public String del(String id,HttpServletRequest request){
		String[] ids = id.split(",");
		for (String string : ids) {
			storeCommentService.deleteById(string);
		}
		return JSONUtils.serialize(new Ret(0));
	}
	
}
